package com.yjhb.android.sbz.fragment.taskmanage;

import android.content.Intent;
import android.view.View;

import com.yjhb.android.sbz.activity.ManagerCenterActivity;
import com.yjhb.android.sbz.adapter.taskmanage.TaskManagerOffAdapter;
import com.yjhb.android.sbz.dialog.TipsDialog;
import com.yjhb.android.sbz.entity.AddTask;
import com.yjhb.android.sbz.entity.ManagerTask;
import com.yjhb.android.sbz.enums.TaskState;
import com.yjhb.android.sbz.mvp.managertasklist.ManagerTaskListView;
import com.yjhb.android.sbz.tool.Tool;

/**
 * 创建者 zx
 * 创建时间 2020/12/10 9:11
 */
public class OffFragment extends BaseTaskManageFragment<TaskManagerOffAdapter> implements ManagerTaskListView {
    private final String TAG = "OtherFragment";

    @Override
    public CharSequence getTitle() {
        return TaskState.TASK_STATE_OFF.getStateStr();
    }

    @Override
    protected TaskManagerOffAdapter getAdapter() {
        return new TaskManagerOffAdapter(getContext());
    }

    @Override
    protected CharSequence getTips() {
        return null;
    }

    @Override
    protected Integer getState() {
        return TaskState.TASK_STATE_OFF.getState();
    }


    @Override
    public void onItemClick(int index, Object o) {
        super.onItemClick(index, o);
        Intent intent = new Intent(getContext(), ManagerCenterActivity.class);
        intent.putExtra("state", getState());
        intent.putExtra("taskId", dataSet.get(index).getTask().getId());
        startActivity(intent);
    }

    @Override
    public void onViewClick(View view, String msg, int index, Object o) {
        super.onViewClick(view, msg, index, o);
        ManagerTask managerTask = (ManagerTask) o;
        if (msg.equals("check")) {
            Tool.startCheckListActivity(getContext(), managerTask);
        } else if (msg.equals("eEdit")) {
            presenter.getDetails(managerTask);
        } else if (msg.equals("delete")) {
            TipsDialog tipsDialog= new TipsDialog(getContext());
            tipsDialog.setTitle("提示");
            tipsDialog.setContent("确定删除？");
            tipsDialog.setSubmitText("确定");
            tipsDialog.setCancelText("取消");
            tipsDialog.setOnClickListener(new TipsDialog.OnClickListener() {
                @Override
                public void onClick(int type) {
                    tipsDialog.dismiss();
                    if (type == TipsDialog.TYPE_SUBMIT){
                        presenter.deleteTask(managerTask.getTask().getId());
                    }
                }
            });
            tipsDialog.show();
        }
    }

    @Override
    public void onTaskDetail(AddTask addTask, ManagerTask managerTask) {
        loadingDialog.cancel();
        Tool.startPublishTaskActivity(getContext(), 2, addTask);
    }


}
